Repository navigation
MATH-1698: Avoid boxing in KendallsCorrelation and document signed zeros - #357
Conversation
|
Discussion issue: https://issues.apache.org/jira/browse/MATH-1698 |
Store the observation pairs as double[] and order them with Double.compare instead of boxing into Pair<Double, Double>. Double.compare matches the previous compareTo/equals semantics, so results are unchanged. Document that values are ordered by Double.compare, so -0.0 and 0.0 are distinct and not counted as a tie, and add a test for it.
40e0394 to
4ee598c
Compare
|
Fair point on underflow. The sign carries real information there, and the class is already consistent with itself, so I've dropped the Reworked along the lines of your comment on MATH-1698. The pairs are now |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #357 +/- ##
============================================
+ Coverage 86.54% 87.23% +0.69%
+ Complexity 9787 91 -9696
============================================
Files 532 499 -33
Lines 35516 33542 -1974
Branches 6194 5856 -338
============================================
- Hits 30738 29262 -1476
+ Misses 3518 3160 -358
+ Partials 1260 1120 -140 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Reworked after the discussion on MATH-1698. Signed zeros stay distinct; the change is now the boxing refactor plus documentation.
The pairs are stored as
double[]and ordered withDouble.compareinstead of being boxed intoPair<Double, Double>.Double.comparereturns 0 exactly whenDouble.equalsis true and orders the same way asDouble.compareTo, so the sort, the merge-sort swap count and the tie scans give the same results as before.The class javadoc now states that values are ordered by
Double.compare, so-0.0sorts below0.0and the two are not counted as a tie.testSignedZerospins that:correlation({0.0, -0.0, 1.0}, {1, 2, 3})is 1/3 andcorrelation({0.0, -0.0}, {1, 2})is -1. It passes against both master and this branch.mvn clean verify javadoc:javadoc -pl commons-math-legacyis green on JDK 21 (3265 tests, 0 Checkstyle violations).